import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';
import eslintPlugin from 'vite-plugin-eslint'
// import ViteComponents, {
//   AntDesignVueResolver,
// } from 'vite-plugin-components';
import styleImport from 'vite-plugin-style-import';
import viteCompression from 'vite-plugin-compression';

// https://vitejs.dev/config/

export default defineConfig({
  plugins: [
    vue(),
    // eslintPlugin()
    // ViteComponents({
    //   customComponentResolvers: [
    //     AntDesignVueResolver(),
    //   ]
    // }),
    styleImport({
      libs: [{
        libraryName: 'ant-design-vue',
        esModule: true,
        resolveStyle: (name) => {
          return `ant-design-vue/es/${name}/style/css`;
        },
      }]
    }),
    [ viteCompression() ]
  ],
  base: './',
  resolve: {
    alias: { '/@': resolve(__dirname, '/src/') }
  },
  build: {
    outDir: 'dist',
    // target: 'es2018',
    minify: 'terser',
    sourcemap: false,
    assetsInlineLimit: 2048,
    cssCodeSplit: true,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },
  server:{
    proxy:{
      '/api': {
        target: 'http://jsonplaceholder.typicode.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    }
  }
})
